/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pwned.memory;

import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.win32.StdCallLibrary;

/**
 *
 * @author Zlobniy
 */
public class MouseEvent {
    
    
    public interface User32 extends StdCallLibrary {
      public static final long MOUSEEVENTF_MOVE = 0x0001L; 
      public static final long MOUSEEVENTF_VIRTUALDESK = 0x4000L; 
      public static final long MOUSEEVENTF_ABSOLUTE = 0x8000L;
      
      public static final int SM_CXSCREEN = 0x0;
      public static final int SM_CYSCREEN = 0x1;
      int GetSystemMetrics(int index);

      User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
      WinDef.DWORD SendInput(WinDef.DWORD dWord, WinUser.INPUT[] input, int cbSize);
   }
    
    public static void mouseMove( int x, int y){
        
      WinUser.INPUT input = new WinUser.INPUT();
      input.type = new WinDef.DWORD(WinUser.INPUT.INPUT_MOUSE);
      
      input.input.setType("mi");
      //input.input.mi.dx = new LONG(500 * 65536 / User32.INSTANCE.GetSystemMetrics(User32.SM_CXSCREEN));
      //input.input.mi.dy = new LONG(500 * 65536 / User32.INSTANCE.GetSystemMetrics(User32.SM_CYSCREEN));
      input.input.mi.dx = new WinDef.LONG(x);
      input.input.mi.dy = new WinDef.LONG(y);
      input.input.mi.mouseData = new WinDef.DWORD(0);
      input.input.mi.dwFlags = new WinDef.DWORD(examples.MouseUtils.User32.MOUSEEVENTF_MOVE
            | examples.MouseUtils.User32.MOUSEEVENTF_VIRTUALDESK | examples.MouseUtils.User32.MOUSEEVENTF_ABSOLUTE);
      // input.input.mi.dwFlags = new DWORD(0x8000L);
      input.input.mi.time = new WinDef.DWORD(0);

      WinUser.INPUT[] inArray = {input};

      int cbSize = input.size(); // mouse input struct size
      WinDef.DWORD nInputs = new WinDef.DWORD(1); // number of inputs
      WinDef.DWORD result = examples.MouseUtils.User32.INSTANCE.SendInput(nInputs , inArray, cbSize);
        
    }
    
}
